1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.collect;
18
19 import static com.google.common.base.Preconditions.checkArgument;
20
21 import com.google.common.collect.testing.features.CollectionFeature;
22 import com.google.common.collect.testing.features.CollectionSize;
23 import com.google.common.collect.testing.features.MapFeature;
24 import com.google.common.collect.testing.google.SetMultimapTestSuiteBuilder;
25 import com.google.common.collect.testing.google.TestStringSetMultimapGenerator;
26
27 import junit.framework.Test;
28 import junit.framework.TestCase;
29
30 import java.io.Serializable;
31 import java.util.Map.Entry;
32
33
34
35
36
37
38
39 public class ConstrainedSetMultimapTest extends TestCase {
40 private enum Constraint implements Serializable, MapConstraint<String, String> {
41 INSTANCE;
42
43 @Override
44 public void checkKeyValue(String key, String value) {
45 checkArgument(!"test".equals(key));
46 checkArgument(!"test".equals(value));
47 }
48 }
49
50 public static Test suite() {
51 return SetMultimapTestSuiteBuilder.using(
52 new TestStringSetMultimapGenerator() {
53
54 @Override
55 protected SetMultimap<String, String> create(Entry<String, String>[] entries) {
56 SetMultimap<String, String> multimap = HashMultimap.create();
57 for (Entry<String, String> entry : entries) {
58 multimap.put(entry.getKey(), entry.getValue());
59 }
60 return MapConstraints.constrainedSetMultimap(multimap, Constraint.INSTANCE);
61 }
62 })
63 .named("MapConstraints.constrainedSetMultimap")
64 .withFeatures(
65 MapFeature.ALLOWS_NULL_KEYS,
66 MapFeature.ALLOWS_NULL_VALUES,
67 MapFeature.ALLOWS_ANY_NULL_QUERIES,
68 MapFeature.GENERAL_PURPOSE,
69 CollectionSize.ANY,
70 CollectionFeature.SERIALIZABLE,
71 CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
72 .createTestSuite();
73 }
74 }